package com.kpatil.erp.impl.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.kpatil.erp.common.HasName;
import com.kpatil.erp.impl.common.ContactTypeDO;

public class InitialData {

	private Map<String, HasName> dataMap = new HashMap<String, HasName>();

	public List<ContactTypeDO> createContactTypes() {
		final List<ContactTypeDO> data = new ArrayList<ContactTypeDO>();
		create(data, new ContactTypeDO(1, "email"));
		create(data, new ContactTypeDO(2, "phone"));
		create(data, new ContactTypeDO(3, "mail"));
		create(data, new ContactTypeDO(4, "im"));
		create(data, new ContactTypeDO(5, "url"));
		return data;
	}

	private <T extends HasName> void create(List<T> data, T object) {
		data.add(object);
		if (dataMap.containsKey(object.getName())) {
			throw new Error("Key already exists");
		}
		dataMap.put(object.getName(), object);
	}

	public static void main(String[] args) {
		final InitialData data = new InitialData();
		data.createContactTypes();

	}
}
